import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart';
import 'package:jd_shop/utils/ToastMsg.dart';

import '../../routers/AppRoutes.dart';
import '../../services/ScreenAdaper.dart';
import '../../utils/Storage.dart';

class Setting extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _SettingState();
  }
}

class _SettingState extends State<Setting> {
  @override
  Widget build(BuildContext context) {
    ScreenAdapter.init(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text("设置"),
      ),
      body: Container(
        margin: EdgeInsets.only(top: ScreenAdapter.width(15), left: ScreenAdapter.width(10), right: ScreenAdapter.width(10)),
        child: ListView(children: <Widget>[
          Container(
            height: ScreenAdapter.width(50),
            decoration:
                const BoxDecoration(color: Colors.white, borderRadius: BorderRadius.only(topLeft: Radius.circular(5), topRight: Radius.circular(5))),
            padding: EdgeInsets.only(left: ScreenAdapter.width(10)),
            child: Stack(
              children: [
                Align(
                  alignment: Alignment.centerLeft,
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(5),
                    // 你可以根据需要调整圆角半径
                    child: Image.asset(
                      "images/yl.png",
                      fit: BoxFit.cover,
                      width: ScreenAdapter.width(32),
                      height: ScreenAdapter.width(32),
                    ),
                  ),
                ),
                Positioned(
                  right: ScreenAdapter.width(10),
                  top: 0,
                  bottom: 0,
                  child: Icon(
                    Icons.arrow_forward_ios,
                    color: Colors.grey,
                    size: ScreenAdapter.width(15),
                  ),
                )
              ],
            ),
          ),
          //增加分割线
          Divider(
            height: ScreenAdapter.width(1),
            indent: ScreenAdapter.width(10),
            endIndent: ScreenAdapter.width(10),
            color: Colors.grey.shade200,
          ),
          InkWell(
            child: Container(
              color: Colors.white,
              child: ListTile(
                title: Text(
                  "加密数据",
                  style: TextStyle(fontSize: ScreenAdapter.fontSize(14)),
                ),
                trailing: Icon(
                  Icons.arrow_forward_ios,
                  color: Colors.grey,
                  size: ScreenAdapter.width(15),
                ),
                onTap: () {
                  var test = "sfsdffsfe";
                  print(md5.convert(utf8.encode(test)));
                  ToastMsg.show(md5.convert(utf8.encode(test)));
                },
              ),
            ),
          ),
          Divider(
            height: ScreenAdapter.width(1),
            indent: ScreenAdapter.width(10),
            endIndent: ScreenAdapter.width(10),
            color: Colors.grey.shade200,
          ),
          InkWell(
            child: Container(
              color: Colors.white,
              child: ListTile(
                title: Text(
                  "视频播放",
                  style: TextStyle(fontSize: ScreenAdapter.fontSize(14)),
                ),
                trailing: Icon(
                  Icons.arrow_forward_ios,
                  color: Colors.grey,
                  size: ScreenAdapter.width(15),
                ),
                onTap: () {
                  Navigator.pushNamed(context, AppRoutes.VIDEO_PAGE);
                },
              ),
            ),
          ),
          Divider(
            height: ScreenAdapter.width(1),
            indent: ScreenAdapter.width(10),
            endIndent: ScreenAdapter.width(10),
            color: Colors.grey.shade200,
          ),
          SizedBox(
            height: ScreenAdapter.width(50),
          ),
          InkWell(
            child: Container(
                alignment: Alignment.center,
                height: ScreenAdapter.height(40),
                margin: EdgeInsets.only(left: ScreenAdapter.width(10), right: ScreenAdapter.width(10)),
                decoration: const BoxDecoration(
                  color: Colors.blue,
                  borderRadius: BorderRadius.all(Radius.circular(5)),
                ),
                child: Text(
                  "退出登录",
                  style: TextStyle(color: Colors.white, fontSize: ScreenAdapter.fontSize(12)),
                )),
            onTap: () {
              //结束当前页面
              Storage.loginOut();
              Navigator.pop(context);
            },
          )
        ]),
      ),
    );
  }
}
